package cn.renxuan.extension.json;

import com.fasterxml.jackson.databind.JsonDeserializer;

public class StringToFloatDeserializer extends JsonDeserializer<Float> {

    @Override
    public Float deserialize(com.fasterxml.jackson.core.JsonParser p,
            com.fasterxml.jackson.databind.DeserializationContext ctxt) throws java.io.IOException {
        String value = p.getText();
        if (value == null || value.isEmpty()) {
            return null;
        }
        try {
            return Float.parseFloat(value);
        } catch (NumberFormatException e) {
            throw new com.fasterxml.jackson.databind.exc.InvalidFormatException(p, "Invalid float value: " + value,
                    value, Float.class);
        }
    }
}
